
package com.crv.ci.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crv.common.domain.view.BizData4Page;
import com.crv.ci.model.PublishTodoParams;
import com.crv.ci.service.IPublishTodoParamsService;
import com.crv.common.utils.IdGenerator;
import com.crv.common.utils.JsonResult;
import com.crv.common.utils.PageParam;
import com.crv.common.utils.Constants;

@Controller
public class PublishTodoParamsAction extends AbstractAdminController<IPublishTodoParamsService>{

    @Autowired
    private IPublishTodoParamsService publishTodoParamsService;
    
    @RequestMapping(value="/publishtodoparams/list")
    public String list(PublishTodoParams publishTodoParams,ModelMap model,PageParam pageParam,HttpServletRequest request,HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(publishTodoParams); 	
    	BizData4Page<PublishTodoParams> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("publishTodoParams", publishTodoParams);
    	return "/module/publishtodoparams/list";
    }    
    
    @RequestMapping(value="/publishtodoparams/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("publishTodoParams", new PublishTodoParams());
        return "module/publishtodoparams/edit";
    }    
    
    @RequestMapping(value="/publishtodoparams/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	PublishTodoParams publishTodoParams = publishTodoParamsService.fetch(id);
    	model.addAttribute("publishTodoParams", publishTodoParams);
        return "module/publishtodoparams/edit";
    }    
    
    @RequestMapping(value="/publishtodoparams/save")
    @ResponseBody
    public String save(HttpServletRequest request,PublishTodoParams publishTodoParams){
		boolean isAddNew = StringUtils.isBlank(publishTodoParams.getId())?true:false;
		if(isAddNew)
		{
			publishTodoParams.setId(IdGenerator.createNewId());
			publishTodoParamsService.add(publishTodoParams);
		}
		else
		{
			publishTodoParamsService.update(publishTodoParams);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/publishtodoparams/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	publishTodoParamsService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(PublishTodoParams publishTodoParams)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("paramName", publishTodoParams.getParamName());		
		conditions.put("publishId", publishTodoParams.getPublishId());		
		conditions.put("paramId", publishTodoParams.getParamId());		
		conditions.put("paramValue", publishTodoParams.getParamValue());		
		conditions.put("createDate", publishTodoParams.getCreateDate());		
    	return conditions;
    }

    @Override
    protected IPublishTodoParamsService getMainService() {
        return publishTodoParamsService;
    }

    @Override
    protected String getMainObjName() {
        return "publishtodoparams";
    }

    @Override
    protected String getViewTitle() {
        return "publishtodoparams";
    }
}
